%Make Figures 4 and 5
load hed_data_log

M = max(hed_m);

num_year = 19;
meancrime = zeros(num_year,1);
for t = 1:num_year
    meancrime(t) = mean(v_crime(year==t));
end
annum = [1:1:19]' + 1989;



num_year = 19;
meancrimec = zeros(num_year,5);
for t = 1:num_year
    for m = 1:M
    meancrimec(t,m) = mean(v_crime(year==t&hed_m==m));
    end
end
annum = [1:1:19]' + 1989;



figure(1)
hold all
[f,xi,bw] = ksdensity(v_crime(hed_m==1),linspace(0,2000,100));
plot(xi,f,'-','Color',[0 0 0] + (1-1)/(1.25*M),'lineWidth',1.5)
[f,xi,bw] = ksdensity(v_crime(hed_m==2),linspace(0,2000,100));
plot(xi,f,'--','Color',[0 0 0] + (2-1)/(1.25*M),'lineWidth',1.5)
[f,xi,bw] = ksdensity(v_crime(hed_m==3),linspace(0,2000,100));
plot(xi,f,'-.','Color',[0 0 0] + (3-1)/(1.25*M),'lineWidth',1.5)
[f,xi,bw] = ksdensity(v_crime(hed_m==4),linspace(0,2000,100));
plot(xi,f,':','Color',[0 0 0] + (4-1)/(1.25*M),'lineWidth',1.5)
[f,xi,bw] = ksdensity(v_crime(hed_m==5),linspace(0,2000,100));
plot(xi,f,'-s','Color',[0 0 0] + (5-1)/(1.25*M),'lineWidth',1.5)
xlabel('Violent Crime Rate','FontSize',16), ylabel('Density','FontSize',16)
h = legend('Alameda',  'Contra Costa', 'Marin', 'San Mateo', 'Santa Clara', 'Location','NorthEast')
set(h, 'fontsize', 14)
myfiguresize = [0, 1, 8.5, 5.0];
set(gcf, 'PaperPosition', myfiguresize);
print -dpng crimeden_bycounty -r200

figure(2)
hold all
plot(annum,meancrimec(:,1),'-','Color',[0 0 0] + (1-1)/(1.25*M),'linewidth', 1.5),
plot(annum,meancrimec(:,2),'--','Color',[0 0 0] + (2-1)/(1.25*M),'linewidth', 1.5),
plot(annum,meancrimec(:,3),'-.','Color',[0 0 0] + (3-1)/(1.25*M),'linewidth', 1.5),
plot(annum,meancrimec(:,4),':','Color',[0 0 0] + (4-1)/(1.25*M),'linewidth', 1.5),
plot(annum,meancrimec(:,5),'-s','Color',[0 0 0] + (5-1)/(1.25*M),'linewidth', 1.5),
xlabel('Year','FontSize',16), ylabel('Violent Crime Rate','FontSize',16)
h = gca;
xlim([1989 2009])
h = legend('Alameda',  'Contra Costa', 'Marin', 'San Mateo', 'Santa Clara', 'Location','NorthEast')
set(h, 'fontsize', 14)
myfiguresize = [0, 1, 8.5, 5.0];
set(gcf, 'PaperPosition', myfiguresize);
print -dpng crime_overtime_bycounty -r200


